package taskit.datastructures;

import taskit.logic.ParserReturnObject;
import taskit.storage.Data;
import taskit.test.Log;

//@author A0087072A
public class CommandDelete extends Command {
	public CommandDelete(Task task, Data data) {
		this.task = task;
		this.data = data;
	}

	@Override
	protected void execute(boolean test) throws Exception {
		Log.add("CommandDelete.java: execute()");
		if (task instanceof Floating) {
			data.delete((Floating) task);
			ParserReturnObject.setAction(ParserReturnObject.ACTION_UPDATE_FT);
			if(test) {
				testResult = CMD_ADD_TODO;
			}
		} else if (task instanceof Schedule) {
			data.delete((Schedule) task);
			ParserReturnObject.setAction(ParserReturnObject.ACTION_UPDATE_DAS);
			if(test) {
				testResult = CMD_ADD_EVENT;
			}
		} else if (task instanceof Deadline) {
			data.delete((Deadline) task);
			ParserReturnObject.setAction(ParserReturnObject.ACTION_UPDATE_DAS);
			if(test) {
				testResult = CMD_ADD_DEADLINE;
			}
		} else {
			throw new Exception("Cannot delete this task.");
		}
	}

	@Override
	public Command reverse() {
		return new CommandAdd(task, data);
	}
}
